特定のaoノードへの接続
コードにao connectを含めると、特定のMUおよびCUに接続する能力と、Arweaveゲートウェイを指定する能力があります。これは、"connect"関数をインポートし、"connect"関数への呼び出しから関数を抽出することで実現できます。
メッセージを送信する際にどのMUが呼び出されているかを知りたい場合、後で指定したMUからデバッグできるようにするために、これを行うことがあります。また、特定のCUから結果を読み取りたい場合もあります。別の理由で特定のMUとCUを好むこともあるかもしれません。デフォルトのarweave.net以外のものを使用するために、ゲートウェイを指定することができます。
connectへの呼び出しなしでのインポート
js
// Here aoconnect will implicitly use the default nodes/units
import {
result,
results,
message,
spawn,
monitor,
unmonitor,
dryrun,
} from "@permaweb/aoconnect";
Connecting to a specific MU, CU, and gateway
js
import { connect } from "@permaweb/aoconnect";
const { result, results, message, spawn, monitor, unmonitor, dryrun } = connect(
{
MU_URL: "https://mu.ao-testnet.xyz",
CU_URL: "https://cu.ao-testnet.xyz",
GATEWAY_URL: "https://arweave.net",
},
);
// now spawn, message, and result can be used the same way as if they were imported directly
All three of these parameters to connect are optional and it is valid to specify only 1 or 2 of them, or none. You could pass in just the MU_URL, for example.
js
import { connect } from "@permaweb/aoconnect";
const { result, results, message, spawn, monitor, unmonitor, dryrun } = connect(
{
MU_URL: "https://ao-mu-1.onrender.com",
},
);